package com.yonyou.crm.common.dubbo.aop;

import java.util.Map;

import com.alibaba.dubbo.rpc.RpcContext;
import com.yonyou.iuap.context.InvocationInfoProxy;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class DubboServiceContextAop {

    @Pointcut("execution(* com.yonyou.crm.*.*.rmitf.*.*(..))")
    public void serviceApi(){

    }

    @Before("serviceApi()")
    public void dubboContext(JoinPoint jp){
    	
        Map<String, String> paraMap = InvocationInfoProxy.getParamters();
        if (paraMap != null && paraMap.size() > 0) {
        	
            for (Map.Entry<String, String> entry : paraMap.entrySet()) {
            	RpcContext.getContext().setAttachment(entry.getKey(), entry.getValue());
            }
        }

        RpcContext.getContext().setAttachment("tenantid", InvocationInfoProxy.getTenantid());
    }

}
